﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using eTMS.Controllers.KhoaHocService;
using eTMS.Controllers.LopService;
using eTMS.Controllers.NganhHocService;
using eTMS.Controllers.SinhVienService;
using eTMS.Controllers;
using eTMS.Commons;
using eTMS.Forms;
using eTMS.Controllers.KhoaService;

namespace eTMS.UserControls
{
    public partial class SinhVienInforView : eTMS.Controls.UserControlBase
    {
        public SinhVienInforView()
        {
            InitializeComponent();
        }
        #region Variables
        private SinhVienController controller;
        public void SetController(SinhVienController _controller)
        {
            controller = _controller;
        }
        #endregion
        #region Screen Functions
        //Load All lable text
        private void LoadLanguage()
        {
            this.Text = Constants.APP_ADDNEW + " " + SinhVienStringMapping.SinhVien;
            labelMaSinhVien.Text = SinhVienStringMapping.MaSinhVien;
            labelTenSinhVien.Text = SinhVienStringMapping.TenSinhVien;
            labelDiaChi.Text = SinhVienStringMapping.DiaChi;
            labelEmail.Text = SinhVienStringMapping.Email;
            labelSoCMND.Text = SinhVienStringMapping.SoCMND;
            labelDienThoai.Text = SinhVienStringMapping.DienThoai;
            labelGhiChu.Text = SinhVienStringMapping.GhiChu;
        }

        //Lock-Unlock control in screen
        public void LockScreen(bool IsLocked)
        {
            txtMaSinhVien.ReadOnly = IsLocked;
            txtTenSinhVien.ReadOnly = IsLocked;
            txtDiaChi.ReadOnly = IsLocked;
            txtEmail.ReadOnly = IsLocked;
            txtSoCMND.ReadOnly = IsLocked;
            txtDienThoai.ReadOnly = IsLocked;
            txtGhiChu.ReadOnly = IsLocked;
            txtLop.ReadOnly = IsLocked;
            txtHeDaoTao.ReadOnly = IsLocked;
            txtKhoa.ReadOnly = IsLocked;
            txtKhoaHoc.ReadOnly = IsLocked;
            txtNganh.ReadOnly = IsLocked;
        }
        //Bind data from object to control in screen
        public void UpdateToScreen()
        {
            SinhVienEntity o = controller.SinhVienObject;
            if (!o.IsNullMaSinhVien)
            {
                txtMaSinhVien.Text = Convert.ToString(o.MaSinhVien);
            }
            if (!o.IsNullTenSinhVien)
            {
                txtTenSinhVien.Text = Convert.ToString(o.TenSinhVien);
            }
            if (!o.IsNullDiaChi)
            {
                txtDiaChi.Text = Convert.ToString(o.DiaChi);
            }
            if (!o.IsNullEmail)
            {
                txtEmail.Text = Convert.ToString(o.Email);
            }
            if (!o.IsNullSoCMND)
            {
                txtSoCMND.Text = Convert.ToString(o.SoCMND);
            }
            if (!o.IsNullDienThoai)
            {
                txtDienThoai.Text = Convert.ToString(o.DienThoai);
            }
            if (!o.IsNullGhiChu)
            {
                txtGhiChu.Text = Convert.ToString(o.GhiChu);
            }
            List<string>list=new List<string>();
            foreach (LopEntity lopEntity in controller.LsLop)
            {
                list.Add(lopEntity.TenLop);
            }
            txtLop.Text = string.Join(",", list.ToArray());
            list = new List<string>();
            foreach (NganhHocEntity nganhHocEntity in controller.LsNganhHoc)
            {
                list.Add(nganhHocEntity.TenNganhHoc);
            }
            txtNganh.Text = string.Join(",", list.ToArray());

            list = new List<string>();
            foreach (KhoaHocEntity khoaHocEntity in controller.LsKhoaHoc)
            {
                list.Add(khoaHocEntity.TenKhoaHoc);
            }
            txtKhoaHoc.Text = string.Join(",", list.ToArray());

            list = new List<string>();
            foreach (KhoaEntity khoaEntity in controller.LsKhoa)
            {
                list.Add(khoaEntity.TenKhoa);
            }
            txtKhoa.Text = string.Join(",", list.ToArray());
        }
        #endregion
        #region Windows Control EventHandlers
        private void SinhVienInforView_Load(object sender, EventArgs e)
        {
            LoadLanguage();
        }

        #endregion
    }
}
